package jp.sourceforge.akjrcp.text_douga.rcp;

import org.eclipse.core.runtime.IExtension;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.registry.ActionSetRegistry;
import org.eclipse.ui.internal.registry.IActionSetDescriptor;

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

	private static final String PERSPECTIVE_ID = Perspective.ID;

    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
        return new ApplicationWorkbenchWindowAdvisor(configurer);
    }

	public String getInitialWindowPerspectiveId() {
		return PERSPECTIVE_ID;
	}
	

	  public void preStartup() {
		 //remove preferences
		  String removePreferences[]={
				  "org.eclipse.ui.preferencePages.Workbench",
				  "org.eclipse.update.internal.ui.preferences.MainPreferencePage"
				  
				
			    	,"jp.sourceforge.akjrcp.flvtools.basic.FLVToolsPage","jp.sourceforge.akjrcp.flvtools.search.SearchPage","jp.sourceforge.akjrcp.flvtools.dvdstyler.DVDStylerPage"
			    	,"jp.sourceforge.akjrcp.dropsomething.FLVConvertPage","jp.sourceforge.akjrcp.flvtools.autoconvert.ExportSettingPage","jp.sourceforge.akjrcp.greycstoration.GreycstorationPage"
			    	,"jp.sourceforge.akjrcp.flvtools.basic.WMVSettingPage","jp.sourceforge.akjrcp.flvtools.basic.AVISettingPage","jp.sourceforge.akjrcp.flvtools.basic.MPEGSettingPage"
			    	,"jp.sourceforge.akjrcp.videotools.VideoToolsSettingPage","jp.sourceforge.akjrcp.psp.PSPSettingPage"
			    	,"jp.sourceforge.akjrcp.dropsomething.H264SettingPage","jp.sourceforge.akjrcp.avisynth.AvisynthPage"
		  };
		  for (int i = 0; i < removePreferences.length; i++) {
			  WorkbenchPlugin.getDefault().getPreferenceManager().remove(removePreferences[i]);
		}
		  
		 //didn't work. 
		 IPerspectiveRegistry reg=WorkbenchPlugin.getDefault().getPerspectiveRegistry();
		 WorkbenchPlugin.getDefault().getPerspectiveRegistry().deletePerspective(reg.findPerspectiveWithId("org.eclipse.ui.resourcePerspective"));
		  
		 //delete actions.
		 
		 ActionSetRegistry areg = WorkbenchPlugin.getDefault().getActionSetRegistry();
	    	IActionSetDescriptor[] actionSets = areg.getActionSets();
	    
	    	
	    	String ignores[]={"org.eclipse.ui.WorkingSetActionSet","org.eclipse.ui.NavigateActionSet","org.eclipse.ui.actionSet.keyBindings","org.eclipse.update.ui.softwareUpdates"
	    			,"akj_betas.actionSet"
	    	};
		  	
	    	
	    	for (int i = 0; i <actionSets.length; i++)
	    	
	    	{
	    		for(int j=0;j<ignores.length;j++){
	    	    if (!actionSets[i].getId().equals(ignores[j]))
	    	
	    	        continue;
	    	
	    	    IExtension ext = actionSets[i].getConfigurationElement()
	    	
	    	        .getDeclaringExtension();
	    	    System.out.println( actionSets[i]);
	    	    areg.removeExtension(ext, new Object[] { actionSets[i] });
	    		}
	    	
	    	}
		  
		
	    
	    }
	  
	  public void postStartup() {
	    	
	    	// System.out.println("postStartup");
	    	
	    	
	    	/*
	    	 * this need for initialize akj
	    	 */
	    	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPerspective(
					PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId("jp.sourceforge.akjrcp.videotools.VideoToolsPerspective")
					
					);
	    	
	    	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().setPerspective(
					PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(PERSPECTIVE_ID)
					
					);
	    	
	  }
}
